﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.ApplicationServer.Http;
using System.Configuration;

namespace RestAndPlay.Player
{
    class RestPlayerWindowsService
    {
        ManualResetEvent wait = new ManualResetEvent(false);

        public void Run()
        {
            //Host the WCF service in a windows service.
            //We start hosting when the service starts and wait with a reset event with the host open.

            var instance = new RestPlayerService();
            using (var host = new HttpServiceHost(instance, ConfigurationManager.AppSettings["ServiceUrl"]))
            {
                host.Open();
                wait.WaitOne();
            }
        }

        public void Stop()
        {
            //When the service ends, we release the reset event, closing the WCF host.

            wait.Set();
        }
    }
}
